package com.dhcc.DRGsHosp.facade.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Named;

import org.apache.shiro.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.dhcc.DRGsHosp.application.DepCliMonitorApplication;
import com.dhcc.DRGsHosp.core.domain.DepGroup;
import com.dhcc.DRGsHosp.facade.DepCliMonitorFacade;
import com.dhcc.DRGsHosp.facade.dto.IndexCalDTO;

/**
 * @title		:DepCliMonitorFacadeImpl.java
 * @description	:
 * @author		:sulina
 * @date		:2015年5月13日
 * @version     :1.0
 * @copyright   :DHCC 2013-2014 
 */
@Named("drgsHospFacadeImpl6")
public class DepCliMonitorFacadeImpl implements DepCliMonitorFacade{

	@Autowired
	private DepCliMonitorApplication depCliMonitorApplication;

	
	@Override
	public Map<String, Object> getDepGroupCodeByDep(IndexCalDTO dto) {
		Map<String, Object> map = new HashMap<String, Object>();
		String depCode = dto.getPardepCode();

		if(StringUtils.hasLength(dto.getPardepCode()))
		{
			List<DepGroup> depGroups = depCliMonitorApplication.getDepGroupCodeByDep(depCode);
			map.put("depGroupCode", depGroups);
		}
		return map;
	}


	@Override
	public Map<String, Object> getDepGroupName(IndexCalDTO dto) {
		Map<String, Object> map = new HashMap<String, Object>();
		String depGroupCode = dto.getPardepgroupCode();

		if(StringUtils.hasLength(dto.getPardepgroupCode()))
		{
			List<DepGroup> depGroups = depCliMonitorApplication.getDepGroupName(depGroupCode);
			map.put("depGroupName", depGroups);
		}
		return map;
	}

	/**
	 * 获取科室组的汇总信息
	 * @param dto
	 * @return shaozhiyuan
	 */
	@Override
	public List<Map<String, Object>> getDepGroupSum(String depCode) {
		List<Map<String, Object>> depGroups = new ArrayList<Map<String, Object>>();
		String depCodeStr="";  //最后拼接的字符串
		if(StringUtils.hasLength(depCode))
		{
			depCode = depCode.replaceAll("\\s*", "");// 去除空格
			String[] depCodeOne = depCode.split(",");
			if (depCodeOne.length > 1) {
				StringBuffer deps = new StringBuffer();
				for (int x = 0; x < depCodeOne.length; x++) {
					deps.append("'" + depCodeOne[x] + "',");
				}
				if(deps.length()>0){
					depCodeStr=deps.substring(0, deps.lastIndexOf(","))+"";
				}
			}else{
				depCodeStr="'"+depCode+"'";
			}
			depGroups = depCliMonitorApplication.getDepGroupSum(depCodeStr);
		}
		return depGroups;
	}

}
